package pri.zxx.learndemo.threademo.base;

import lombok.extern.slf4j.Slf4j;
import pri.zxx.webdemo.utils.TimeUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author Twilight
 * @desc
 * @createTime 2020-06-26-22:18
 */
@Slf4j
public class JoinDemo {
    public static void main(String[] args) throws InterruptedException {
        List<Thread> collect = IntStream.rangeClosed(0, 1).mapToObj(JoinDemo::create).collect(Collectors.toList());
        collect.forEach(Thread::start);
        for (Thread thread : collect) {
            thread.join();
        }
        JoinDemo.brief();
    }

    public static Thread create(Integer i) {
        return new Thread(JoinDemo::brief, "join-test-" + i);
    }

    public static void brief() {
        IntStream.range(0, 9).forEach((s) -> {
            TimeUtils.pause(0, 1, 0);
            System.out.println(Thread.currentThread().getName() + "#" + s);
        });
    }
}
